package cn.edu.controller;

import cn.edu.pojo.Dept;
import cn.edu.service.DeptService;
import cn.edu.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Mr.ma
 * @since 2022/12/7 19:13
 **/
@RestController
@RequestMapping("/dept")
@Api("部门操作API")
public class DeptController {
    @Resource
    private DeptService deptService;

    @ApiOperation("根据id获取部门信息")
    @RequestMapping("selectById")
    @ApiImplicitParam(name = "id", value = "部门编号", dataType = "int")
    public ResultVO selectById(Integer id) {
        Dept dept = deptService.selectById(id);
        return new ResultVO(200,"查询成功",dept);
    }

    @ApiOperation("根据id删除部门信息")
    @RequestMapping("deleteById")
    @ApiImplicitParam(name = "id", value = "部门编号", dataType = "int")
    public ResultVO deleteById(Integer id) {
        int delete = deptService.deleteById(id);
        if (delete > 0){
            return new ResultVO(200,"删除成功",null);
        }
        return new ResultVO(500,"删除失败",null);
    }

    @ApiOperation("根据id修改部门信息")
    @RequestMapping("updateById")
    public ResultVO updateById(Dept dept){
        int i = deptService.updateById(dept);
        if (i > 0){
            return new ResultVO(200,"修改成功",null);
        }
        return new ResultVO(500,"修改失败",null);
    }

    @ApiOperation("插入部门信息")
    @RequestMapping("insert")
    public ResultVO insert(Dept dept){
        int insert = deptService.insert(dept);
        if (insert > 0){
            return new ResultVO(200,"插入成功",null);
        }
        return new ResultVO(500,"插入失败",null);
    }

    @ApiOperation("根据id获取部门信息")
    @RequestMapping("selectByIdAnn")
    @ApiImplicitParam(name = "id", value = "部门编号", dataType = "int")
    public ResultVO selectByIdAnn(Integer id) {
        Dept dept = deptService.selectByIdAnn(id);
        return new ResultVO(200,"查询成功",dept);
    }

    @ApiOperation("根据id删除部门信息")
    @RequestMapping("deleteByIdAnn")
    @ApiImplicitParam(name = "id", value = "部门编号", dataType = "int")
    public ResultVO deleteByIdAnn(Integer id) {
        int delete = deptService.deleteByIdAnn(id);
        if (delete > 0){
            return new ResultVO(200,"删除成功",null);
        }
        return new ResultVO(500,"删除失败",null);
    }

    @ApiOperation("根据id修改部门信息")
    @RequestMapping("updateByIdAnn")
    public ResultVO updateByIdAnn(Dept dept){
        int i = deptService.updateByIdAnn(dept);
        if (i > 0){
            return new ResultVO(200,"修改成功",null);
        }
        return new ResultVO(500,"修改失败",null);
    }
}
